package com.kuang.controller.pfsi;

import com.kuang.pojo.AstControllerHeart;
import com.kuang.pojo.pfsi.AstPfsiDeviceRegister;
import com.kuang.service.asset.AstControllerHeartService;
import com.kuang.service.pfsi.AstPfsiDeviceRegisterService;
import lombok.extern.log4j.Log4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/asset/")
@Log4j
public class AstPfsiDeviceRegisterController {

    @Resource
    AstPfsiDeviceRegisterService astPfsiDeviceRegisterService;

    /**
     * 获取全部数据
     * @param model
     * @return
     */
    @RequestMapping("getAstPfsiDeviceRegisters")
    public String getAstPfsiDeviceRegisters(Model model){
        List<AstPfsiDeviceRegister> astPfsiDeviceRegisters = astPfsiDeviceRegisterService.selectAll();
        model.addAttribute("datas",astPfsiDeviceRegisters);
        model.addAttribute("device_code","");
        model.addAttribute("ver","");
        return "pfsi/ast_pfsi_device_register_list";
    }

    /**
     * 获取数据通过条件
     * @param model
     * @return
     */
    @PostMapping("getAstPfsiDeviceRegistersByExample")
    public String getAstPfsiDeviceRegistersByExample(AstPfsiDeviceRegister astPfsiDeviceRegister,Model model){
        List<AstPfsiDeviceRegister> astPfsiDeviceRegisters = astPfsiDeviceRegisterService.selectAllByExample(astPfsiDeviceRegister);
        model.addAttribute("datas",astPfsiDeviceRegisters);
        model.addAttribute("device_code",astPfsiDeviceRegister.getDevice_code());
        model.addAttribute("ver",astPfsiDeviceRegister.getVer());
        return "pfsi/ast_pfsi_device_register_list";
    }

    /**
     * 获取设备信息通过id
     * @param model
     * @return
     */
    @RequestMapping("getAstPfsiDeviceRegistersById/{id}")
    public String getAstPfsiDeviceRegistersById(@PathVariable("id") String id, Model model){
        AstPfsiDeviceRegister astPfsiDeviceRegister = new AstPfsiDeviceRegister();
        astPfsiDeviceRegister.setAst_pfsi_device_register_id(id);
        List<AstPfsiDeviceRegister> astPfsiDeviceRegisters = astPfsiDeviceRegisterService.selectAllByExample(astPfsiDeviceRegister);
        model.addAttribute("data",astPfsiDeviceRegisters.get(0));
        return "pfsi/ast_pfsi_device_register_from";
    }

}
